package com.prs.crm.dao.crm.impl;


import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Property;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.domain.crm.CodeNumber;
import com.prs.crm.domain.crm.Configure;
import com.prs.crm.domain.crm.DispatchBook;

public class CodeNumberDaoImpl extends BaseDaoImpl<CodeNumber> implements com.prs.crm.dao.crm.CodeNumberDao{

	@SuppressWarnings("unchecked")
	@Override
	public CodeNumber getCodeByState(final String state) {
		return (CodeNumber) this.getHibernateTemplate().execute(
				new HibernateCallback(){
					@Override
					public Object doInHibernate(Session arg0)
							throws HibernateException, SQLException {
						Criteria criteria = arg0.createCriteria(CodeNumber.class);
						criteria.add(Restrictions.eq("state", state));
						List<DispatchBook> alist=criteria.list();
						if(alist.size()==0){
							return null;
						}else{
							return alist.get(0);
						}
					}
				}
			);
	}

	@Override
	public List<CodeNumber> getAllCodeNumber() {
		Criteria criteria = this.getSession().createCriteria(CodeNumber.class);
		return criteria.list();
	}

}
